package org.xerial.silk.editor.plugin.text;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
import org.eclipse.jface.text.rules.Token;
import org.xerial.util.log.Logger;

public class SilkPartitionScanner extends RuleBasedPartitionScanner
{
    private static Logger _logger = Logger.getLogger(SilkPartitionScanner.class);

    public SilkPartitionScanner() {
        super();

        IToken silkPreamble = new Token(SilkPartitions.SILK_PREAMBLE);
        IToken silkComment = new Token(SilkPartitions.SILK_COMMENT);
        IToken silkNode = new Token(SilkPartitions.SILK_NODE);
        IToken silkFunction = new Token(SilkPartitions.SILK_FUNCTION);

        List<IPredicateRule> rules = new ArrayList<IPredicateRule>();

        rules.add(new EndOfLineRule("%", silkPreamble));
        rules.add(new EndOfLineRule("#", silkComment));
        rules.add(new EndOfLineRule("@", silkFunction));
        rules.add(new EndOfLineRule("-", silkNode));

        IPredicateRule[] result = new IPredicateRule[rules.size()];
        rules.toArray(result);
        setPredicateRules(result);
    }

}
